package com.yc.tomcat.impl;

import com.yc.tomcat.HttpServletRequest;
import com.yc.tomcat.HttpServletResponse;
import com.yc.tomcat.HttpSession;
import com.yc.tomcat.ServletException;

import java.io.IOException;
import java.io.PrintWriter;

public class LoginServlet extends HttpServletImpl{

    @Override
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        response.setContentType("text/html;charset=utf-8");
        PrintWriter out = response.getWriter();
        if("yc".equals(username) && "123".equals(password)){
            HttpSession session = request.getSession();
            session.setAttribute("loginedUser", username);
            out.println("登录成功!");
            out.println("<a href='form.html'>返回首页</a>");
        } else {
            out.println("用户名或密码错误!");
            out.println("<a href='form.html'>返回首页</a>");
        }
    }

}
